package baseTest;

import java.util.HashSet;

public class Three {
    public static void main(String[] args) {
        for (int i = 123; i*3<=987; i++) {
            if (isTrue(i)){
                System.out.print(i+" ");
                System.out.print(i*2+" ");
                System.out.print(i*3+" ");
                System.out.println();
            }
        }
    }
    public static boolean isTrue(int n){
        String N = n + "";
        String twoN = n*2 + "";
        String threeN = n*3 + "";
        HashSet<Character> strings = new HashSet<>();
        for (int i = 0; i < N.length(); i++) {
            if (strings.isEmpty()){
                strings.add(N.charAt(i));
            }else if (strings.contains(N.charAt(i))){
                return false;
            }else {
                strings.add(N.charAt(i));
            }
        }
        for (int i = 0; i < twoN.length(); i++) {
            if (strings.isEmpty()){
                strings.add(twoN.charAt(i));
            }else if (strings.contains(twoN.charAt(i))){
                return false;
            }else {
                strings.add(twoN.charAt(i));
            }
        }

        for (int i = 0; i < threeN.length(); i++) {
            if (strings.isEmpty()){
                strings.add(threeN.charAt(i));
            }else if (strings.contains(threeN.charAt(i))){
                return false;
            }else {
                strings.add(threeN.charAt(i));
            }
        }
        if (strings.contains('0')){
            return false;
        }
        return true;
    }
}

